<template>
	<view class="Shell" :style="appBoolean&&Android?'padding-top:60rpx':`padding-top:${wh}px`">
		<!-- 头部 -->
		<web-top v-if="platForm=='web'&&!appBoolean||Android" title="交易详情" :module="module"></web-top>
		<view class="header" v-else-if="platForm=='mp-weixin'">
			<view class="h-back" @click="backFn">
				<image :src="`${masterDomain}/static/images/header_back.png?v=${imgVersion}`" mode="aspectFit"></image>
			</view>
			<view class="h-text">交易详情</view>
		</view>
		<!-- 订单详情 -->
		<view class="succeed" v-if="orderInfo.state==1">
			<view class="s-title">
				<image :src="`${imgurl}success.png?v=${imgVersion}`" mode="aspectFit"></image>
				<text>交易成功</text>
			</view>
			<view class="s-detail">
				<view class="sd-item">
					<text class="title">交易金额</text>
					<text class="money">￥{{orderInfo.amount}}</text>
				</view>
				<view class="sd-item">
					<text class="title">打赏文章</text>
					<text class="intro">{{orderInfo.title}}</text>
				</view>
				<view class="sd-item">
					<text class="title">交易时间</text>
					<text class="intro">{{orderInfo.date}}</text>
				</view>
				<view class="sd-item">
					<text class="title">交易单号</text>
					<text class="intro">{{orderInfo.ordernum}}</text>
				</view>
			</view>
		</view>
		<view class="failed" v-else>
			<view class="f-title">
				<image :src="`${imgurl}error.png?v=${imgVersion}`" mode="aspectFit"></image>
				<text>抱歉，打赏失败!</text>
			</view>
			<view class="f-kefu">如有问题，请联系客服：{{siteConfig.hotline}}</view>
		</view>
		<private_tip :privateShow="privateb"></private_tip>
	</view>
</template>

<script>
	var _this;
	const app = getApp();
	import webTop from '../../uni_modules/web/components/webTop/webTop.vue'
	export default {
		components: { //组件注册
			webTop
		},
		data() {
			return {
				imgVersion: app.globalData.imgVersion,
				imgurl: app.globalData.imgPath + '/article/',
				masterDomain: app.globalData.masterDomain,
				wh: app.globalData.navTop || 0,
				siteConfig: '',
				// 接口数据
				// 辅助数据
				ordernum: '', //必传
				orderInfo: {},
				module: '', //必传
				// 组件数据
				info: '',
				privateb: false,
				// 布尔变量
				ajaxb: false,
				// 兼容项
				platForm: '',
				Android: false,
				appBoolean: false,
			}
		},
		onLoad(options) {
			_this = this;
			if (app.globalData.wxprivate == -1) {
				app.watchG('wxprivate', function(value) {
					_this.wxprivate = value;
					if (value) { //弹出弹窗
						_this.privateb = true;
					} else {
						_this.onload(options);
					}
				})
			} else {
				if (app.globalData.wxprivate) { //弹出弹窗
					_this.privateb = true;
				} else {
					_this.onload(options);
				}
			}
		},
		methods: {
			onload(options) {
				_this.ordernum = options.ordernum;
				_this.module = options.module || '';
				if (app.globalData.siteConfig.hotline) { //配置
					_this.siteConfig = app.globalData.siteConfig;
				} else {
					app.watchG('siteConfig', function(value) {
						_this.siteConfig = value;
					});
				}
				// 平台切换
				_this.platForm = app.globalData.platForm;
				if (_this.platForm == 'web') {
					_this.Android = window.Android;
					_this.appBoolean = window.appBoolean;
					_this.module = _this.module || window.moldName;
				}
				_this.orderData();
			},
			backFn() { //后退函数
				if (_this.appBoolean) { //APP
					window.setupWebViewJavascriptBridge(function(bridge) {
						bridge.callHandler("goBack", {}, function(responseData) {});
					})
					return false
				} else {
					let canNavBack = getCurrentPages();
					if (canNavBack && canNavBack.length > 1) {
						uni.navigateBack({
							delta: 1
						});
					} else {
						uni.redirectTo({
							url: _this.orderInfo.url || `/pages/packages/${_this.module}/index/index`,
						})
					}
				}
			},
			orderData() {
				let data = {
					service: _this.module,
					action: 'orderDetail',
					ordernum: _this.ordernum
				}
				_this.$ajax.post({
					url: 'include/ajax.php?',
					data: data
				}).then(res => {
					if (res.data.state == 100) {
						_this.orderInfo = res.data.info;
					}
				})
			}
		},
	}
</script>

<style>
	@import url("index");
</style>